package com.payment.system.domain.wxpay;

import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;

public class WxAppPay {
	private String appId;
	private String partnerId;
	private String prepayId;
	private String nonceStr;
	private String timeStamp;
	private String packageStr;
	private String sign;

	public WxAppPay(WxUnifiedOrderResp unifiedOrderResp) {
		this.appId = WxAppPayConfig.instance().appId;
		this.partnerId = WxAppPayConfig.instance().mchId;
		this.prepayId = unifiedOrderResp.getPrepayId();
		this.nonceStr = UUID.randomUUID().toString().trim().replaceAll("-", "");
		this.timeStamp = Long.toString(System.currentTimeMillis()/1000);
		this.packageStr = "Sign=WXPay";
		this.sign = createSign();
	}

	private String createSign() {
		SortedMap<String, Object> m = new TreeMap<>();
		m.put("appid", this.appId);
		m.put("partnerid", this.partnerId);
		m.put("prepayid", this.prepayId);
		m.put("noncestr", this.nonceStr);
		m.put("timestamp", this.timeStamp);
		m.put("package", this.packageStr);
		return WxPayUtil.sign(m);
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public String getPartnerId() {
		return partnerId;
	}

	public void setPartnerId(String partnerId) {
		this.partnerId = partnerId;
	}

	public String getPrepayId() {
		return prepayId;
	}

	public void setPrepayId(String prepayId) {
		this.prepayId = prepayId;
	}

	public String getNonceStr() {
		return nonceStr;
	}

	public void setNonceStr(String nonceStr) {
		this.nonceStr = nonceStr;
	}

	public String getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(String timeStamp) {
		this.timeStamp = timeStamp;
	}

	public String getPackageStr() {
		return packageStr;
	}

	public void setPackageStr(String packageStr) {
		this.packageStr = packageStr;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

}
